using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Admin_Admin_SelectProduct : Admin, IRequiresSessionState
{
	protected ScriptManager sm;
	protected TextBox ProductList;
	protected HiddenField hfProductList;
	protected UpdatePanel upOk;
	protected DropDownList ddlClassFirst;
	protected DropDownList ddlClassSecond;
	protected DropDownList ddlClassThree;
	protected DropDownList ddlClassFour;
	protected UpdatePanel upanClass;
	protected TextBox txtProductName;
	protected Button SeachBut;
	protected GridView gvManage;
	protected Button btnSelected;
	protected Literal ltrPagePanel;
	protected UpdatePanel upProduct;
	protected HtmlForm productform;
	private string linkHead = "";
	private Shop_Class shopclass;
	private string selectedClassFirst = "";
	private string selectedClassSecond = "";
	private string selectedClassThree = "";
	private string selectedClassFour = "";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	public Shop_Class Shopclass
	{
		get
		{
			if (this.shopclass == null)
			{
				this.shopclass = new Shop_Class(this.conn);
			}
			return this.shopclass;
		}
	}
	public string SelectedClassFirst
	{
		get
		{
			if (this.ddlClassFirst.Items.Count > 0)
			{
				this.selectedClassFirst = this.ddlClassFirst.SelectedValue;
			}
			return this.selectedClassFirst;
		}
		set
		{
			this.selectedClassFirst = value;
		}
	}
	public string SelectedClassSecond
	{
		get
		{
			if (this.ddlClassSecond.Items.Count > 0)
			{
				this.selectedClassSecond = this.ddlClassSecond.SelectedValue;
			}
			return this.selectedClassSecond;
		}
		set
		{
			this.selectedClassSecond = value;
		}
	}
	public string SelectedClassThree
	{
		get
		{
			if (this.ddlClassThree.Items.Count > 0)
			{
				this.selectedClassThree = this.ddlClassThree.SelectedValue;
			}
			return this.selectedClassThree;
		}
		set
		{
			this.selectedClassThree = value;
		}
	}
	public string SelectedClassFour
	{
		get
		{
			if (this.ddlClassFour.Items.Count > 0)
			{
				this.selectedClassFour = this.ddlClassFour.SelectedValue;
			}
			return this.selectedClassFour;
		}
		set
		{
			this.selectedClassFour = value;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(20))
			{
				base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Product");
				base.WriteRightErrMsg();
			}
			this.hfProductList.Value = Fetch.Get("DefaultValue");
			if (!string.IsNullOrEmpty(this.hfProductList.Value))
			{
				string sql = "select ProductID,ProductName from HLShop_Product where ProductID in (" + this.hfProductList.Value + ")";
				DataTable dataTable = this.conn.GetDataTable(sql);
				string text = "";
				string text2 = "";
				string[] array = this.hfProductList.Value.Split(new char[]
				{
					','
				});
				for (int i = 0; i < dataTable.Rows.Count; i++)
				{
					text = text + dataTable.Rows[i]["ProductName"].ToString() + ",";
					text2 = text2 + dataTable.Rows[i]["ProductID"].ToString() + ",";
				}
				if (text != "")
				{
					text = text.Substring(0, text.Length - 1);
					text2 = text2.Substring(0, text2.Length - 1);
				}
				this.ProductList.Text = text;
				this.hfProductList.Value = text2;
			}
			this.BindClassFirst();
			this.BindProduct();
		}
	}
	protected void BindProduct()
	{
		CurrPageLinks currPageLinks = new CurrPageLinks();
		string query = this.GetQuery();
		int num = this.gvManage.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		ClientByPage clientByPage = new ClientByPage();
		string text = " from HLShop_Product,HLShop_Class where (ProductType=1 or  ProductType=4) and HLShop_Class.ClassID=HLShop_Product.ClassID ";
		int pageSize = this.gvManage.PageSize;
		int listCount = clientByPage.GetListCount("select count(*)" + text + query);
		string url = "?DefaultValue=" + this.hfProductList.Value + this.linkHead + "&pageindex";
		int startIndex = (num - 1) * pageSize + 1;
		int endIndex = num * pageSize;
		string str = " ROW_NUMBER() OVER (order by ProductID desc) as row,ProductID,ProductName,ProductSmallImageUrl,Stocks,StandPrice,SalerID,ProductType,ClassName";
		string strSQL = "select " + str + text + query;
		DataTable listPage = clientByPage.GetListPage(strSQL, "row", startIndex, endIndex);
		this.gvManage.DataSource = listPage;
		this.gvManage.DataBind();
		if (listPage.Rows.Count > 0)
		{
			this.ltrPagePanel.Text = currPageLinks.CurrPageLink(num, pageSize, listCount, "条记录&nbsp;&nbsp;每页&nbsp;" + pageSize + "&nbsp;条数据&nbsp;&nbsp;", url);
		}
	}
	public string GetProductTypeStr(object ProductType)
	{
		string result = "";
		string text = ProductType.ToString();
		if (text != null)
		{
			if (!(text == "4"))
			{
				if (text == "1")
				{
					result = "一口价";
				}
			}
			else
			{
				result = "促销(秒杀)";
			}
		}
		return result;
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("ProductName");
		if (!string.IsNullOrEmpty(text2))
		{
			if (text2 != this.txtProductName.Text.Trim())
			{
				text2 = this.txtProductName.Text.Trim();
			}
			this.txtProductName.Text = text2;
		}
		else
		{
			text2 = this.txtProductName.Text;
		}
		if (!string.IsNullOrEmpty(text2))
		{
			text = text + " and ProductName like '%" + text2 + "%'";
			this.linkHead = this.linkHead + "&ProductName=" + text2;
		}
		string text3 = Fetch.Get("selectclass");
		if (!string.IsNullOrEmpty(text3))
		{
			text3 = this.ddlSelect(this.ddlClassFour, text3);
			text3 = this.ddlSelect(this.ddlClassThree, text3);
			text3 = this.ddlSelect(this.ddlClassSecond, text3);
			text3 = this.ddlSelect(this.ddlClassFirst, text3);
		}
		if (!string.IsNullOrEmpty(this.SelectedClassFirst))
		{
			text3 = this.SelectedClassFirst;
		}
		if (!string.IsNullOrEmpty(this.SelectedClassSecond))
		{
			text3 = this.SelectedClassSecond;
		}
		if (!string.IsNullOrEmpty(this.SelectedClassThree))
		{
			text3 = this.SelectedClassThree;
		}
		if (!string.IsNullOrEmpty(this.SelectedClassFour))
		{
			text3 = this.SelectedClassFour;
		}
		if (text3 != "")
		{
			text = text + " and HLShop_Product.ClassID=" + text3;
			this.linkHead = this.linkHead + "&selectclass=" + text3;
		}
		return text;
	}
	private string ddlSelect(DropDownList ddl, string selectValue)
	{
		DataTable classByClassID = this.Shopclass.GetClassByClassID(Convert.ToInt32(selectValue));
		for (int i = 0; i < ddl.Items.Count; i++)
		{
			ddl.Items[i].Selected = false;
			if (ddl.Items[i].Value == selectValue)
			{
				ddl.Items[i].Selected = true;
				selectValue = ddl.SelectedValue.Trim();
				break;
			}
		}
		return selectValue;
	}
	protected void gvManage_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void gvManage_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvManage.PageIndex = e.NewPageIndex;
		this.BindProduct();
	}
	protected void SeachBut_Click(object sender, EventArgs e)
	{
		this.BindProduct();
	}
	protected void BindClassFirst()
	{
		this.ddlClassSecond.Style["display"] = "none";
		this.ddlClassThree.Style["display"] = "none";
		this.ddlClassFour.Style["display"] = "none";
		this.ddlClassFirst.Items.Clear();
		ListItem item = new ListItem(Language.Get("Common/Choose"), "");
		this.ddlClassFirst.Items.Add(item);
		this.ddlClassFirst.DataSource = this.Shopclass.GetRootClass();
		this.ddlClassFirst.DataTextField = "ClassName";
		this.ddlClassFirst.DataValueField = "ClassID";
		this.ddlClassFirst.DataBind();
		if (!string.IsNullOrEmpty(this.SelectedClassFirst))
		{
			foreach (ListItem listItem in this.ddlClassFirst.Items)
			{
				if (listItem.Value == this.SelectedClassFirst)
				{
					listItem.Selected = true;
					break;
				}
			}
		}
	}
	protected void BindClassChild(DropDownList ddl, string ParentID)
	{
		ddl.Items.Clear();
		if (ddl.SelectedIndex != 0)
		{
			if (!string.IsNullOrEmpty(ParentID))
			{
				DataTable childClassByParnetID = this.Shopclass.GetChildClassByParnetID(Convert.ToInt32(ParentID));
				if (childClassByParnetID != null)
				{
					ListItem item = new ListItem(Language.Get("Common/Choose"), "");
					ddl.Items.Add(item);
					ddl.DataSource = childClassByParnetID;
					ddl.DataTextField = "ClassName";
					ddl.DataValueField = "ClassID";
					ddl.DataBind();
				}
			}
		}
	}
	protected void ddlClassFirst_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.ddlClassSecond.Style["display"] = "none";
		this.ddlClassThree.Style["display"] = "none";
		this.ddlClassFour.Style["display"] = "none";
		this.ddlClassSecond.Items.Clear();
		this.ddlClassThree.Items.Clear();
		this.ddlClassFour.Items.Clear();
		if (!string.IsNullOrEmpty(this.SelectedClassFirst))
		{
			this.ddlClassSecond.Style["display"] = "";
			this.ddlClassThree.Style["display"] = "none";
			this.ddlClassFour.Style["display"] = "none";
			this.BindClassChild(this.ddlClassSecond, this.SelectedClassFirst);
			if (!string.IsNullOrEmpty(this.SelectedClassSecond))
			{
				foreach (ListItem listItem in this.ddlClassSecond.Items)
				{
					if (listItem.Value == this.SelectedClassSecond)
					{
						listItem.Selected = true;
						break;
					}
				}
			}
		}
	}
	protected void ddlClassSecond_SelectedIndexChanged(object sender, EventArgs e)
	{
		if (!string.IsNullOrEmpty(this.SelectedClassSecond))
		{
			this.ddlClassThree.Style["display"] = "";
			this.ddlClassFour.Style["display"] = "none";
			this.BindClassChild(this.ddlClassThree, this.SelectedClassSecond);
			if (!string.IsNullOrEmpty(this.SelectedClassThree))
			{
				foreach (ListItem listItem in this.ddlClassThree.Items)
				{
					if (listItem.Value == this.SelectedClassThree)
					{
						listItem.Selected = true;
						break;
					}
				}
			}
		}
	}
	protected void ddlClassThree_SelectedIndexChanged(object sender, EventArgs e)
	{
		if (!string.IsNullOrEmpty(this.SelectedClassThree))
		{
			this.ddlClassFour.Style["display"] = "";
			this.BindClassChild(this.ddlClassFour, this.SelectedClassThree);
			if (!string.IsNullOrEmpty(this.SelectedClassFour))
			{
				foreach (ListItem listItem in this.ddlClassFour.Items)
				{
					if (listItem.Value == this.SelectedClassFour)
					{
						listItem.Selected = true;
						break;
					}
				}
			}
		}
	}
}
